#ifndef AbcLoader_H
#define AbcLoader_H

#include "abc_context.h"
#include "abckit_apis.h"
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <regex>
#include <type_traits>
#include <algorithm>
#include <iostream>
#include <memory>
#include <type_traits>

AbcContext::~AbcContext()
{
    g_impl->closeFile(this->file);
}

namespace abccontext
{

    AbcContext AbcContextImpl = {};

    bool endsWith(const std::string &str, const std::string &suffix)
    {
        if (str.length() < suffix.length())
            return false;
        return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
    }

    bool validateAndExtractPath(const std::string &input, std::vector<std::string> &extractedParts)
    {
        // 定义更严格的正则表达式模式
        std::regex pattern(R"(&([a-zA-Z_][a-zA-Z0-9_]*)/src/main/ets(/([a-zA-Z0-9_]+))+&([\d\.a-zA-Z]*))");
        std::smatch matches;
        // 尝试匹配输入字符串
        if (std::regex_match(input, matches, pattern))
        {
            extractedParts.clear();

            // 提取第一个部分(entry)
            std::regex prefixRegex(R"(&([a-zA-Z_][a-zA-Z0-9_]*)/src/main/ets)");
            std::smatch prefixMatch;
            if (std::regex_search(input, prefixMatch, prefixRegex))
            {
                extractedParts.push_back(prefixMatch[1].str());
            }
            std::regex pathRegex(R"(.*?/src/main/ets(/.*?)&([\d\.a-zA-Z]*))");
            std::smatch pathMatch;
            if (std::regex_search(input, pathMatch, pathRegex))
            {
                extractedParts.push_back(pathMatch[1].str());
            }
            return true;
        }
        return false;
    }

    void parsePath(std::string moduleName, std::shared_ptr<AbcPath> &abcPath)
    {
        abcPath->originModulePath = moduleName;
        std::vector<std::string> extracted;
        if (validateAndExtractPath(moduleName, extracted) && extracted.size() == 2)
        {
            abcPath->module = extracted[0];
            abcPath->package = extracted[1];
        }
        else
        {
            abcPath->package = moduleName;
        }
    }

    AbcFuncType idfAbcFuncType(AbckitCoreFunction *function, std::string funcName)
    {
        if (funcName == "func_main_0")
        {
            return AbcFuncType::MAIN_ABC_FUNC_TYPE;
        }
        if (g_implI->functionIsAnonymous(function))
        {
            return AbcFuncType::ANONYMOUS_ABC_FUNC_TYPE;
        }

        return AbcFuncType::NORMAL_ABC_FUNC_TYPE;
    }

    void packageFunction(AbckitCoreFunction *function, std::shared_ptr<AbcFunc> &abcFunc)
    {
        abcFunc->func = function;
        abcFunc->name = g_implI->abckitStringToString(g_implI->functionGetName(function));
        abcFunc->type = idfAbcFuncType(function, abcFunc->name);
        abcFunc->isStatic = g_implI->functionIsStatic(function);
    }

    void moduleEnumerateFunctions(std::shared_ptr<AbcNode<AbckitCoreModule>> &node)
    {
        g_implI->moduleEnumerateTopLevelFunctions(node->curNode, &node, [](AbckitCoreFunction *method, void *data)
                                                  {
                auto& moduleNode = *static_cast<std::shared_ptr<AbcNode<AbckitCoreModule>> *>(data);
                auto abcFunc = std::make_shared<AbcFunc>();
                abcFunc->parentModule = moduleNode;
                abcFunc->parentClass = std::shared_ptr<AbcNode<AbckitCoreClass>>();
                abcFunc->parentNamespace = std::shared_ptr<AbcNode<AbckitCoreNamespace>>();
                packageFunction(method,abcFunc);
                moduleNode->methods.emplace_back(abcFunc);
                return true; });
    }

    // 1.1
    std::shared_ptr<AbcNode<AbckitCoreModule>> packageModuleNode(AbckitCoreModule *module)
    {
        auto moduleNode = std::make_shared<AbcNode<AbckitCoreModule>>();
        moduleNode->parentModule = std::shared_ptr<AbcNode<AbckitCoreModule>>();
        moduleNode->parentNS = std::shared_ptr<AbcNode<AbckitCoreNamespace>>();
        moduleNode->type = AbcNodeType::MODULE_ABC_NODE_TYPE;
        moduleNode->curNode = module;
        moduleNode->path = std::make_shared<AbcPath>();

        std::string moduleName = g_implI->abckitStringToString(g_implI->moduleGetName(module));
        moduleNode->name = moduleName;
        parsePath(moduleName, moduleNode->path);
        moduleEnumerateFunctions(moduleNode);
        return moduleNode;
    }

    template <typename T>
    struct NodeEnumerateContext
    {
        AbcContext *context;
        std::shared_ptr<AbcNode<T>> node;
    };

    std::shared_ptr<AbcNode<AbckitCoreClass>> initClassNode(std::shared_ptr<AbcNode<AbckitCoreModule>> &moduleNode, std::shared_ptr<AbcNode<AbckitCoreNamespace>> &nsNode)
    {
        auto classNode = std::make_shared<AbcNode<AbckitCoreClass>>();
        classNode->parentModule = moduleNode;
        classNode->type = AbcNodeType::CLASS_ABC_NODE_TYPE;
        classNode->path = std::make_unique<AbcPath>();
        if (nsNode)
        {
            classNode->path->module = nsNode->path->module;
            classNode->path->namespaces = nsNode->path->namespaces;
            classNode->path->originModulePath = nsNode->path->originModulePath;
            classNode->path->package = nsNode->path->package;
        }
        else
        {
            classNode->path->module = moduleNode->path->module;
            classNode->path->namespaces = moduleNode->path->namespaces;
            classNode->path->originModulePath = moduleNode->path->originModulePath;
            classNode->path->package = moduleNode->path->package;
        }

        classNode->parentModule = moduleNode;
        classNode->parentNS = nsNode;
        return classNode;
    }

    void classEnumerateFunctions(std::shared_ptr<AbcNode<AbckitCoreClass>> &classNode)
    {
        g_implI->classEnumerateMethods(classNode->curNode, &classNode, [](AbckitCoreFunction *method, void *data)
                                       {
                auto& classNode = *static_cast<std::shared_ptr<AbcNode<AbckitCoreClass>> *>(data);
                auto abcFunc = std::make_shared<AbcFunc>();
                abcFunc->parentClass = classNode;
                abcFunc->parentModule = std::shared_ptr<AbcNode<AbckitCoreModule>>();
                abcFunc->parentNamespace = std::shared_ptr<AbcNode<AbckitCoreNamespace>>();
                packageFunction(method,abcFunc);
                classNode->methods.emplace_back(abcFunc);
                return true; });
    }

    void mouduleBuildClassNode(AbcContext *abccontext, std::shared_ptr<AbcNode<AbckitCoreModule>> &moduleNode)
    {

        NodeEnumerateContext<AbckitCoreModule> classNodeEnumerateContext;
        classNodeEnumerateContext.context = abccontext;
        classNodeEnumerateContext.node = moduleNode;
        g_implI->moduleEnumerateClasses(moduleNode->curNode, &classNodeEnumerateContext, [](AbckitCoreClass *cls, void *data)
                                        {
            NodeEnumerateContext<AbckitCoreModule> *context =reinterpret_cast<NodeEnumerateContext<AbckitCoreModule> *>(data);
            auto emptyNsNode = std::shared_ptr<AbcNode<AbckitCoreNamespace>>();
            auto classNode = initClassNode(context->node, emptyNsNode);
            classNode->curNode = cls;
            classNode->name = g_implI->abckitStringToString(g_implI->classGetName(cls));
            classEnumerateFunctions(classNode);
            context->context->classNodes.emplace_back(classNode);
            return true; });
    }

    std::shared_ptr<AbcNode<AbckitCoreNamespace>> initNamespaceNode(std::shared_ptr<AbcNode<AbckitCoreModule>> &moduleNode, std::shared_ptr<AbcNode<AbckitCoreNamespace>> &nsNode)
    {
        auto node = std::make_shared<AbcNode<AbckitCoreNamespace>>();
        node->type = AbcNodeType::NAMESPACE_ABC_NODE_TYPE;
        node->path = std::make_unique<AbcPath>();
        if (nsNode)
        {
            node->path->module = nsNode->path->module;
            node->path->namespaces = nsNode->path->namespaces;
            node->path->originModulePath = nsNode->path->originModulePath;
            node->path->package = nsNode->path->package;
        }
        else
        {
            node->path->module = moduleNode->path->module;
            node->path->namespaces = moduleNode->path->namespaces;
            node->path->originModulePath = moduleNode->path->originModulePath;
            node->path->package = moduleNode->path->package;
        }
        node->parentModule = moduleNode;
        node->parentNS = nsNode;
        return node;
    }

    void namespaceEnumerateFunctions(std::shared_ptr<AbcNode<AbckitCoreNamespace>> &nsNode)
    {
        g_implI->namespaceEnumerateTopLevelFunctions(nsNode->curNode, &nsNode, [](AbckitCoreFunction *method, void *data)
                                                     {
                auto& nsNode = *static_cast<std::shared_ptr<AbcNode<AbckitCoreNamespace>> *>(data);
                auto abcFunc = std::make_shared<AbcFunc>();
                abcFunc->parentNamespace = nsNode;
                abcFunc->parentModule = std::shared_ptr<AbcNode<AbckitCoreModule>>();
                abcFunc->parentClass = std::shared_ptr<AbcNode<AbckitCoreClass>>();
                packageFunction(method,abcFunc);
                nsNode->methods.emplace_back(abcFunc);
                return true; });
    }

    void namespaceBuildClassNode(AbcContext *abccontext, std::shared_ptr<AbcNode<AbckitCoreNamespace>> &nsNode)
    {
        NodeEnumerateContext<AbckitCoreNamespace> nsEnumerateContext;
        nsEnumerateContext.context = abccontext;
        nsEnumerateContext.node = nsNode;
        g_implI->namespaceEnumerateClasses(nsNode.get()->curNode, &nsEnumerateContext, [](AbckitCoreClass *cls, void *data)
                                           {
            auto *context =reinterpret_cast<NodeEnumerateContext<AbckitCoreNamespace> *>(data);
            auto emptyModuleNode = std::shared_ptr<AbcNode<AbckitCoreModule>>();
            auto classNode = initClassNode(emptyModuleNode, context->node);
            classNode->curNode = cls;
            classNode->name = g_implI->abckitStringToString(g_implI->classGetName(cls));
            classEnumerateFunctions(classNode);
            context->context->classNodes.emplace_back(classNode);
            return true; });
    }

    void namespaceBuildNamespaceNode(AbcContext *abccontext, std::shared_ptr<AbcNode<AbckitCoreNamespace>> &nsNode)
    {
        NodeEnumerateContext<AbckitCoreNamespace> nsNodeEnumerateContext;
        nsNodeEnumerateContext.context = abccontext;
        nsNodeEnumerateContext.node = nsNode;
        g_implI->namespaceEnumerateNamespaces(nsNode->curNode, &nsNodeEnumerateContext, [](AbckitCoreNamespace *n, void *data)
                                              {
            NodeEnumerateContext<AbckitCoreNamespace> *context =reinterpret_cast<NodeEnumerateContext<AbckitCoreNamespace> *>(data);
            auto emptyModuleNode = std::shared_ptr<AbcNode<AbckitCoreModule>>();
            auto nsNode = initNamespaceNode(emptyModuleNode, context->node);
            nsNode->curNode = n;
            nsNode->name = nsNode->name + "." +g_implI->abckitStringToString(g_implI->namespaceGetName(n));
            nsNode->path->namespaces =  nsNode->name;

            namespaceEnumerateFunctions(context->node);
            context->context->namespaceNodes.emplace_back(context->node);

            // 构造namespace-classNode
            namespaceBuildClassNode(context->context,context->node);

            // 构造namespace-namespace
            namespaceBuildNamespaceNode(context->context,context->node);

            return true; });
    }

    void mouduleBuildNamespace(AbcContext *abccontext, std::shared_ptr<AbcNode<AbckitCoreModule>> &moduleNode)
    {
        NodeEnumerateContext<AbckitCoreModule> nsNodeEnumerateContext;
        nsNodeEnumerateContext.context = abccontext;
        nsNodeEnumerateContext.node = moduleNode;

        g_implI->moduleEnumerateNamespaces(moduleNode->curNode, &nsNodeEnumerateContext, [](AbckitCoreNamespace *n, void *data)
                                           {
            NodeEnumerateContext<AbckitCoreModule> *context =reinterpret_cast<NodeEnumerateContext<AbckitCoreModule> *>(data);
            auto emptyNsNode = std::shared_ptr<AbcNode<AbckitCoreNamespace>>();
            auto nsNode = initNamespaceNode(context->node, emptyNsNode);
            nsNode->curNode = n;
            nsNode->name = g_implI->abckitStringToString(g_implI->namespaceGetName(n));
            namespaceEnumerateFunctions(nsNode);
            context->context->namespaceNodes.emplace_back(nsNode);

            // 构造namespace-classNode
            namespaceBuildClassNode(context->context,nsNode);

            // 构造namespace-namespace
            namespaceBuildNamespaceNode(context->context,nsNode);

            return true; });
    }

    void idfFuncType(const std::shared_ptr<AbcNode<AbckitCoreClass>> &cls, const std::shared_ptr<AbcFunc> &method)
    {
        std::string clsName = cls->name;
        if (method->type == AbcFuncType::ATTRSET_ABC_FUNC_TYPE || method->type == AbcFuncType::ATTRGET_ABC_FUNC_TYPE)
        {
            return;
        }
        if (method->name == clsName && !method->isStatic)
        {
            method->type = AbcFuncType::CONSTRUCTOR_ABC_FUNC_TYPE;
            return;
        }
        if (method->name == "initialRender" && !method->isStatic)
        {
            method->type = AbcFuncType::BUILD_ABC_FUNC_TYPE;
            return;
        }
        if (method->name == "updateStateVars" && !method->isStatic)
        {
            method->type = AbcFuncType::SYSTEM_ABC_FUNC_TYPE;
            return;
        }
        if (method->name == "setInitiallyProvidedValue" && !method->isStatic)
        {
            method->type = AbcFuncType::SYSTEM_ABC_FUNC_TYPE;
            return;
        }
        if (method->name == "rerender" && !method->isStatic)
        {
            method->type = AbcFuncType::SYSTEM_ABC_FUNC_TYPE;
            return;
        }
        if (method->name == "purgeVariableDependenciesOnElmtId" && !method->isStatic)
        {
            method->type = AbcFuncType::SYSTEM_ABC_FUNC_TYPE;
            return;
        }
        if (method->name == "getEntryName")
        {
            method->type = AbcFuncType::SYSTEM_ABC_FUNC_TYPE;
            return;
        }

        if (method->name == "aboutToBeDeleted" || method->name == "aboutToBeDeleted" || method->name == "onBackup" || method->name == "onRestore" || method->name == "onBackground" || method->name == "onCreate" || method->name == "onDestroy" || method->name == "onForeground" || method->name == "onWindowStageCreate" || method->name == "onWindowStageDestroy")
        {
            method->type = AbcFuncType::LIFECYCLE_ABC_FUNC_TYPE;
            return;
        }

        std::string methodName = method->name;
        auto it = std::find_if(cls->methods.begin(), cls->methods.end(), [methodName](std::shared_ptr<AbcFunc> m)
                               { return m->name == methodName + "^1" || m->name + "^1" == methodName; });
        if (it != cls->methods.end())
        {
            if (endsWith(methodName, "^1"))
            {
                method->type = AbcFuncType::ATTRSET_ABC_FUNC_TYPE;
                (*it)->type = AbcFuncType::ATTRGET_ABC_FUNC_TYPE;
            }
            else
            {
                method->type = AbcFuncType::ATTRGET_ABC_FUNC_TYPE;
                (*it)->type = AbcFuncType::ATTRSET_ABC_FUNC_TYPE;
            }
        }
    }

    void idfFuncType(AbcContext *abccontext)
    {
        for (const auto &cls : abccontext->classNodes)
        {
            for (const auto &method : cls->methods)
            {
                idfFuncType(cls, method);
            }
        }
    }

    std::map<std::string, std::shared_ptr<AbcFunc>> collectAnonymousFunctions(std::vector<std::shared_ptr<AbcFunc>> methods,
                                                                              std::shared_ptr<AbcNode<AbckitCoreModule>> parentModule,
                                                                              std::shared_ptr<AbcNode<AbckitCoreNamespace>> parentNS)
    {
        std::map<std::string, std::shared_ptr<AbcFunc>> anonymousFunctions;
        std::for_each(methods.begin(), methods.end(), [&anonymousFunctions](std::shared_ptr<AbcFunc> func)
                      {
            if(func->type == AbcFuncType::ANONYMOUS_ABC_FUNC_TYPE){
                // std::cout << "已知匿名函数:" << func->name << std::endl;
                anonymousFunctions.insert(std::make_pair(func->name,func));
            } });

        if (parentNS)
        {
            std::for_each(parentNS->methods.begin(), parentNS->methods.end(), [&anonymousFunctions](std::shared_ptr<AbcFunc> func)
                          {
                if(func->type == AbcFuncType::ANONYMOUS_ABC_FUNC_TYPE){
                    // std::cout << "已知匿名函数:" << func->name << std::endl;
                    anonymousFunctions.insert(std::make_pair(func->name,func));
                } });
            return anonymousFunctions;
        }

        if (parentModule)
        {
            std::for_each(parentModule->methods.begin(), parentModule->methods.end(), [&anonymousFunctions](std::shared_ptr<AbcFunc> func)
                          {
                if(func->type == AbcFuncType::ANONYMOUS_ABC_FUNC_TYPE){
                    // std::cout << "已知匿名函数:" << func->name << std::endl;
                    anonymousFunctions.insert(std::make_pair(func->name,func));
                } });
        }
        return anonymousFunctions;
    }

    struct FuncRelContext
    {
        std::map<std::string, std::shared_ptr<AbcFunc>> anonymousFunctions;
        std::shared_ptr<AbcFunc> method;
        std::shared_ptr<AbcFunc> rootMethod;
        bool hasChild = false;
        std::set<std::shared_ptr<AbcFunc>> methods;
    };

    void recursionGetAnonymousFuns(std::map<std::string, std::shared_ptr<AbcFunc>> &anonymousFunctions,
                                   std::shared_ptr<AbcFunc> &rootMethod, const std::shared_ptr<AbcFunc> &curMethod)
    {
        FuncRelContext context;
        context.anonymousFunctions = anonymousFunctions;
        context.method = curMethod;
        context.rootMethod = rootMethod;

        AbckitGraph *graph = g_implI->createGraphFromFunction(curMethod->func);
        g_implG->gVisitBlocksRpo(graph, &context, [](AbckitBasicBlock *basicBlock, void *data)
                                 {
            FuncRelContext *context = reinterpret_cast<FuncRelContext *>(data);
            AbckitInst *inst = g_implG -> bbGetFirstInst(basicBlock);
            while(inst != nullptr){
                if(g_dynG -> iGetOpcode(inst) == ABCKIT_ISA_API_DYNAMIC_OPCODE_DEFINEFUNC){
                    AbckitCoreFunction *targetMethod = g_implG -> iGetFunction(inst);
                    std::string parentN = context->method->name;
                    auto n = g_implI -> abckitStringToString(g_implI -> functionGetName(targetMethod));
                    // std::cout << parentN << "找到匿名函数:" << n << std::endl;
                    // context->method->anonymousFuncs.insert();
                    auto it = context->anonymousFunctions.find(n);
                    if (it != context->anonymousFunctions.end()) {
                        std::shared_ptr<AbcFunc> anonymousFunc = it->second;
                        context->method->anonymousFuncs.insert(anonymousFunc);
                        context->rootMethod->anonymousFuncs.insert(anonymousFunc);
                        context->hasChild = true;
                        context->methods.insert(anonymousFunc);
                    }
                }
                inst = g_implG -> iGetNext(inst);
            }
            return true; });

        if (!context.hasChild)
            return;
        for (auto &m : context.methods)
        {
            recursionGetAnonymousFuns(anonymousFunctions, rootMethod, m);
        }
    }

    void recuSearchLambdaParentFunc(AbcContext *abccontext)
    {
        auto classNodes = abccontext->classNodes;

        std::for_each(classNodes.begin(), classNodes.end(), [](std::shared_ptr<AbcNode<AbckitCoreClass>> node)
                      {
            std::map<std::string,std::shared_ptr<AbcFunc>> anonymousFunctions = collectAnonymousFunctions(node->methods,node->parentModule,node->parentNS);
            std::for_each(node->methods.begin(), node->methods.end(), [&anonymousFunctions](std::shared_ptr<AbcFunc> method) {
                if(method->type == AbcFuncType::ANONYMOUS_ABC_FUNC_TYPE){
                    return;
                }
                recursionGetAnonymousFuns(anonymousFunctions,method,method);
            }); });

        auto moduleNodes = abccontext->moduleNodes;

        std::for_each(moduleNodes.begin(), moduleNodes.end(), [](std::shared_ptr<AbcNode<AbckitCoreModule>> node)
                      {
            std::map<std::string,std::shared_ptr<AbcFunc>> anonymousFunctions = collectAnonymousFunctions(node->methods,node->parentModule,node->parentNS);
            std::for_each(node->methods.begin(), node->methods.end(), [&anonymousFunctions](std::shared_ptr<AbcFunc> method) {
                if(method->type == AbcFuncType::ANONYMOUS_ABC_FUNC_TYPE){
                    return;
                }
                recursionGetAnonymousFuns(anonymousFunctions,method,method);
            }); });
    }

    void deleteEmptyNode(AbcContext *abccontext)
    {
        abccontext->moduleNodes.erase(std::remove_if(abccontext->moduleNodes.begin(), abccontext->moduleNodes.end(), [](std::shared_ptr<AbcNode<AbckitCoreModule>> m)
                                                     { return m->methods.size() == 0; }),
                                      abccontext->moduleNodes.end());
        abccontext->namespaceNodes.erase(std::remove_if(abccontext->namespaceNodes.begin(), abccontext->namespaceNodes.end(), [](std::shared_ptr<AbcNode<AbckitCoreNamespace>> m)
                                                        { return m->methods.size() == 0; }),
                                         abccontext->namespaceNodes.end());
        abccontext->classNodes.erase(std::remove_if(abccontext->classNodes.begin(), abccontext->classNodes.end(), [](std::shared_ptr<AbcNode<AbckitCoreClass>> m)
                                                    { return m->methods.size() == 0; }),
                                     abccontext->classNodes.end());
    }

    void abcNodeGetMethods(AbcContext *context)
    {
        std::vector<std::shared_ptr<AbcFunc>> methods;
        std::for_each(context->moduleNodes.begin(), context->moduleNodes.end(), [&methods](std::shared_ptr<AbcNode<AbckitCoreModule>> node)
                      { std::for_each(node->methods.begin(), node->methods.end(), [&methods](std::shared_ptr<AbcFunc> method)
                                      {
                if(method->type == AbcFuncType::NORMAL_ABC_FUNC_TYPE || method->type == AbcFuncType::BUILD_ABC_FUNC_TYPE || method->type == AbcFuncType::LIFECYCLE_ABC_FUNC_TYPE){
                    methods.emplace_back(method);
                } }); });
        std::for_each(context->namespaceNodes.begin(), context->namespaceNodes.end(), [&methods](std::shared_ptr<AbcNode<AbckitCoreNamespace>> node)
                      { std::for_each(node->methods.begin(), node->methods.end(), [&methods](std::shared_ptr<AbcFunc> method)
                                      {
                if(method->type == AbcFuncType::NORMAL_ABC_FUNC_TYPE || method->type == AbcFuncType::BUILD_ABC_FUNC_TYPE || method->type == AbcFuncType::LIFECYCLE_ABC_FUNC_TYPE){
                    methods.emplace_back(method);
                } }); });

        std::for_each(context->classNodes.begin(), context->classNodes.end(), [&methods](std::shared_ptr<AbcNode<AbckitCoreClass>> node)
                      { std::for_each(node->methods.begin(), node->methods.end(), [&methods](std::shared_ptr<AbcFunc> method)
                                      {
                if(method->type == AbcFuncType::NORMAL_ABC_FUNC_TYPE || method->type == AbcFuncType::BUILD_ABC_FUNC_TYPE || method->type == AbcFuncType::LIFECYCLE_ABC_FUNC_TYPE){
                    methods.emplace_back(method);
                } }); });
        context->methods = methods;
    }

    void loadAbcNodes(AbcContext *abcContext, std::string abc_path)
    {
        AbckitFile *file = g_impl->openAbc(abc_path.c_str(), strlen(abc_path.c_str()));
        abcContext->file = file;
        g_implI->fileEnumerateModules(file, abcContext, [](AbckitCoreModule *module, void *data)
                                      {
            // 创建ModuleNode 1.0
            AbcContext *context =reinterpret_cast<AbcContext *>(data);
            auto moduleNode = packageModuleNode(module);
            context->moduleNodes.emplace_back(moduleNode);
            // 创建ClassNode
            mouduleBuildClassNode(context,moduleNode);
            // 创建NamespaceNode
            mouduleBuildNamespace(context,moduleNode);

            return true; });

        deleteEmptyNode(abcContext);
        idfFuncType(abcContext);
        recuSearchLambdaParentFunc(abcContext);
        abcNodeGetMethods(abcContext);
    };

};

AbcContext const *AbcContextApiImpl(std::string abc_path)
{

    abccontext::AbcContextImpl.abc_path = abc_path;
    abccontext::loadAbcNodes(&abccontext::AbcContextImpl, abc_path);
    return &abccontext::AbcContextImpl;
}

#endif AbcLoader_H